package com.lagou.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

@RestController
public class HelloController {
    @RequestMapping
    public String demo() throws SQLException {
        //获取数据库连接对象
        Connection connection = MySqlConn.newConnection();
        Statement statement = connection.createStatement();
        ResultSet resultSet = statement.executeQuery("select * from user");
        StringBuilder stringBuilder = new StringBuilder();
        while (resultSet.next()) {
            stringBuilder.append(resultSet.getInt("id") + ", "
                    + resultSet.getString("username") + ", "
                    + resultSet.getString("sex") + ", "
                    + resultSet.getInt("age") + "; ");
        }
        System.out.println(stringBuilder);
        JDBCConnPool.close(connection, statement, resultSet);
        return stringBuilder.toString();
    }
}
